package com.worldstear.utils;

import cn.hutool.core.io.FileUtil;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.Objects;

public class FileUtils {

    static String url;

    static {
        String usrDir = System.getProperty("user.dir");
        url = usrDir + "/Node1";
        File file = FileUtil.file(url);
        if(!file.exists()) {
            boolean mkdirs = file.mkdirs();
        }
    }

    public static File saveMultipartFile(MultipartFile file) throws Exception {
        if(Objects.isNull(file)) {
            throw new Exception("file not found");
        }
        File _file = new File(url + File.separator + file.getOriginalFilename());
        file.transferTo(_file);
        return _file;
    }


}
